home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Printing / LaserWriter 8 API / New API sample / PSAdobe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-17  |  5.4 KB  |  196 lines  |  [TEXT/KAHL]

  1. /*
  2.     
  3.     File name: PSAdobe.c
  4.     
  5.     This file contain sample code for using the new PrGeneral APIs.
  6.     
  7. */
  8.  
  9. #include <PrintTraps.h>
  10. #include <string.h>
  11. #include "ATMInterface.h"
  12. #include "PSAdobe.h"
  13.  
  14. void main(void);
  15. OSErr commOut(Ptr buffer, long nBytes);
  16.  
  17. static struct {
  18.     Handle data;
  19.     long len;
  20. } out, fnts = {0, 0}, eps = {0, 0};
  21.  
  22.  
  23. #define pCopy(dest, src) BlockMove(src, dest, src[0]+1)
  24.  
  25. void main() {
  26.     short fi;
  27.     long count;
  28.     TPSAdobe a;
  29.     unsigned short i, n;
  30.     TPSPrimaryPPD ppd;
  31.     
  32.     InitGraf(&thePort);
  33.     InitFonts();
  34.     FlushEvents(everyEvent, 0);
  35.     InitWindows();
  36.     InitMenus();
  37.     TEInit();
  38.     InitDialogs(0L);
  39.     InitCursor();
  40.     
  41.     PrOpen();
  42.     fnts.len = eps.len = 0;
  43.     if (PrDrvrVers() >= 80 && PrDrvrVers() < 100) {    /* API only available with PSWriter */
  44.         
  45.         /*** Name of PPD file ***/
  46.         
  47.         ppd.iOpCode = PSPrimaryPPDOp;
  48.         ppd.lReserved = 0;
  49.         PrGeneral((Ptr)&ppd);
  50.         if (ppd.ppdIsRealFile) {        /* has the user selected a real PPD file? */
  51.             /* ppd.ppdFile is a file spec for the main PPD file. See doc for System 7 for
  52.                examples of how to use it.
  53.             */
  54.         }
  55.         
  56.         
  57.         /*** Handle fonts ***/
  58.         
  59.         out.len = 0;
  60.         out.data = NewHandle(0);        /* prepare our call back stuff. See commOut() below. */
  61.         
  62.         a.iOpCode = PSAdobeOp;
  63.         a.lReserved = 0;
  64.         a.reserved = 0;                    /* always set reserved fields to zero */
  65.         a.appFlags = 0;                    /* our flags */
  66.         a.version = kPSAdobeVersion;    /* tell driver which version of PSAdobe we know about */
  67.         a.op = commOut;                    /* we use the same proc for gathering data in all cases */
  68.         a.binary = false;                /* same as control in Print:Save:Binary/ASCII
  69.         a.level2 = false;                /* false == level1 compatible, true == level 2 only */
  70.         
  71.         /* prepare to get info for fonts */
  72.         a.subId = PSFontInfo;
  73.         a.is.fontInfo.data = (TPSAdobe **)NewHandle(0);    /* global data */
  74.         a.is.fontInfo.printerClass = kCNone;
  75.         a.is.fontInfo.calcVMusage = false;    /* we don't need the VMusage in this example */
  76.         
  77.         /* get info for fonts. */
  78.         GetFNum("\pN Helvetica Narrow", &a.is.fontInfo.id);
  79.         a.is.fontInfo.style = 0;
  80.         a.is.fontInfo.psName[0] = 0;        /* indicates that id/style specifies the font */
  81.         PrGeneral((Ptr)&a);
  82.         a.is.fontInfo.id = geneva;
  83.         a.is.fontInfo.style = 0;
  84.         a.is.fontInfo.psName[0] = 0;
  85.         PrGeneral((Ptr)&a);
  86.         pCopy(a.is.fontInfo.psName, "\pMyriadMM_245_LT_520_SE");
  87.         PrGeneral((Ptr)&a);
  88.         pCopy(a.is.fontInfo.psName, "\pDummyFontName");    /* should come back with a.iError == fnfErr */
  89.         PrGeneral((Ptr)&a);
  90.         /* a.is.fontInfo.data now contain all info we need for these fonts */
  91.         
  92.         /* get definitions */
  93.         HLock((Handle)a.is.fontInfo.data);
  94.         n = GetHandleSize((Handle)a.is.fontInfo.data)/sizeof(**a.is.fontInfo.data);
  95.         /* n is number of reources in a.is.fontInfo.data */
  96.         
  97.         for (i = 0; i < n; ++i) {
  98.             PrGeneral((Ptr)&(*a.is.fontInfo.data)[i]);    /* now data is sent to commOut */
  99.         }
  100.         
  101.         HUnlock((Handle)a.is.fontInfo.data);
  102.         DisposHandle((Handle)a.is.fontInfo.data);
  103.         
  104.         fnts = out;
  105.         
  106.         
  107.         /*** PICT to EPS conversion ***/
  108.         
  109.         /* Note that pict to eps has to be done outside PrOpenDoc/PrCloseDoc */
  110.         
  111.         out.len = 0;
  112.         out.data = NewHandle(0);                /* prepare to download an eps */
  113.         
  114.         a.subId = PSpict2eps;
  115.         a.is.pict2eps.getPicProc = nil;
  116.         a.is.pict2eps.includeFonts = includeNoFonts;
  117.         a.is.pict2eps.title = "\pMy Picture";
  118.         a.is.pict2eps.unlimitedFonts = 0;
  119.         a.is.pict2eps.textSmoothing = 0;
  120.         a.is.pict2eps.graphicsSmoothing = 0;
  121.         a.is.pict2eps.color = kColor;
  122.         a.is.pict2eps.fontSubstitution = true;
  123.         a.is.pict2eps.reserved = 0;
  124.         a.is.pict2eps.pict = GetPicture(128);    /* from PSAdobe.π.rsrc */
  125.         PrGeneral((Ptr)&a);
  126.         eps = out;
  127. #ifdef __NEVER__
  128.             
  129.             /*** comPostScriptFile ***/
  130.             
  131.             The app might want to save the ps code to a file, and then included
  132.             after PrOpenDoc as PSHandles.
  133.             An alternative way would be to put the file in some folder, and then
  134.             use the comPostScriptFile pic comment to send the name of the file to
  135.             the driver. The app can specify that the file should be removed after
  136.             it has been used. The format for this comment is:
  137.             {    Ptr p;
  138.                 Handle h
  139.                 
  140.                 p = "\pThor:file1.eps";
  141.                 if (removeWhenDone) {
  142.                     h = NewHandle(p[0]+1 + 1);        /* make room for delete marker */
  143.                     (*h)[p[0]+1] = 1;                /* delete file when we're done */
  144.                 }
  145.                 else {
  146.                     h = NewHandle(p[0]+1);            /* just make room for file name */
  147.                 }
  148.                 BlockMove(p, *h, p[0]+1);            /* copy the file name */
  149.                 PicComment(comPostScriptFile, GetHandleSize(h), h);
  150.             }
  151. #endif
  152.  
  153.         if (fnts.len) {    /* dump fonts */
  154.             Create("\pfnts.out", 0, 'KAHL', 'TEXT');
  155.             FSOpen("\pfnts.out", 0, &fi);
  156.             SetEOF(fi, 0);
  157.             count = fnts.len;
  158.             FSWrite(fi, &count, *fnts.data);
  159.             FSClose(fi);
  160.             DisposHandle(fnts.data);
  161.         }
  162.         if (eps.len) {    /* dump eps */
  163.             Create("\peps.out", 0, 'KAHL', 'TEXT');
  164.             FSOpen("\peps.out", 0, &fi);
  165.             SetEOF(fi, 0);
  166.             count = eps.len;
  167.             FSWrite(fi, &count, *eps.data);
  168.             FSClose(fi);
  169.             DisposHandle(eps.data);
  170.         }
  171.     }
  172.     PrClose();
  173. }
  174.  
  175.  
  176. OSErr commOut(Ptr buffer, long nBytes) {
  177.     /* stuff output data data */
  178.     
  179.     if (out.len + nBytes > GetHandleSize(out.data)) {
  180.         SetHandleSize(out.data, out.len + nBytes + 0x4000);
  181.         if (MemError())
  182.             return MemError();
  183.     }
  184.     BlockMove(buffer, *out.data + out.len, nBytes);
  185.     out.len += nBytes;
  186.     return noErr;
  187. }
  188.  
  189. /* Note: commOut above will be called a zillion times, often with just a few bytes. There
  190.    is no internal buffering before the call to commOut, so you better have your own. Usually,
  191.    this is often done later. For example, writing this to disk or sending it through PAP should
  192.    be OK, they have their own buffering.
  193. */
  194.  
  195.  
  196.